package nio;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

/**
 * Created by Administrator on 2017/10/22 022.
 */
public class FileVisitorDemo
{
    public static void main(String[] args)
    {
        try
        {
            Files.walkFileTree(Paths.get("D:\\itellijIdea_wk\\JavaDemo"), new SimpleFileVisitor<Path>()
            {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
                {
                    System.out.println("正在访问 --> " + file.getFileName());
                    return super.visitFile(file, attrs);
                }

                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException
                {
                    System.out.println("正在访问路径 --> " + dir.getFileName());
                    return super.preVisitDirectory(dir, attrs);
                }
            });
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
